let fetch: any;
export const clearAsync = (func: any, args: any) => {
  let cache: { status: string; data: null; err: null; }[] = [];
  let i = 0;
  const _originFetch = fetch;
  const promise = fetch = (...args: any) => {
    if (cache[i].status === 'fulfilled') {
      return cache[i].data;
    } else if (cache[i].status === 'rejected') {
      throw cache[i].err;
    }
    const result = {
      status: 'pending',
      data: null,
      err: null
    };
    cache[i++] = result;
    _originFetch(...args).then((resp: any) => resp.json()).then(
    (resp: any) => {
      result.status = 'fulfilled';
      result.data = resp;
    }, (err: any) => {
      result.status = 'rejected';
      result.err = err;
    })
    throw promise;
  };
  try {
    func(args);
  } catch (err: any) {
    const reRun = () => {
      i = 0;
      func(args);
    }
    err.then(reRun, reRun);
  }
}